package com.example.star.mapper;

import com.example.star.entity.Message;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper {
    @Insert("INSERT INTO messages (star_name, username, message, send_time) VALUES (#{starName}, #{userName}, #{message}, NOW())")
    void insertMessage(Message message);

    @Select("SELECT * FROM messages WHERE star_name = #{starName} ORDER BY send_time ASC")
    List<Message> getMessagesByStarName(String starName);

    @Select("SELECT * FROM messages WHERE star_name = #{starName}")
    List<Message> getAllMessagesByStarName(String starName);

    @Select("SELECT * FROM messages WHERE username = #{userName}")
    List<Message> getuserNames(String userName);
}
